package com.zhangxun.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangxun.domain.IndexImg;
import com.zhangxun.domain.Prod;
import com.zhangxun.feign.StoreProdFeign;
import com.zhangxun.service.IndexImgService;
import com.zhangxun.mapper.IndexImgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 张循
* @description 针对表【index_img(主页轮播图)】的数据库操作Service实现
* @createDate 2023-01-05 18:32:47
*/
@Service
public class IndexImgServiceImpl extends ServiceImpl<IndexImgMapper, IndexImg>
    implements IndexImgService{

    @Autowired
    private StoreProdFeign storeProdFeign;

    @Autowired
    private IndexImgMapper indexImgMapper;

    @Override
    public Page<IndexImg> selectPage(Page<IndexImg> page, IndexImg indexImg) {
        page = indexImgMapper.selectPage(page,new LambdaQueryWrapper<IndexImg>()
                .eq(ObjectUtil.isNotNull(indexImg.getStatus()),IndexImg::getStatus,indexImg.getStatus()));

        return page;
    }

    @Override
    public IndexImg selectById(Long indexId) {

        IndexImg indexImg = indexImgMapper.selectById(indexId);

        Long prodId = indexImg.getRelation();

        Prod prod = storeProdFeign.getById(prodId);
        indexImg.setProdName(prod.getProdName());
        indexImg.setPic(prod.getPic());
        return indexImg;
    }
}




